package com.hkd.common.data.config.type_handler;

import com.hkd.common.api.convert.OrderStatusConvert;
import com.hkd.common.api.enums.IdentityCardType;
import com.hkd.common.api.enums.OrderStatus;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedJdbcTypes;
import org.apache.ibatis.type.MappedTypes;
import org.springframework.stereotype.Component;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author HKD
 * @date 2022/9/19 0:03
 */
@Component
@MappedTypes(OrderStatus.class)
@MappedJdbcTypes(value = JdbcType.TINYINT, includeNullJdbcType = true)
public class OrderStatusHandler extends BaseTypeHandler<OrderStatus> {
    @Override
    public void setNonNullParameter(PreparedStatement preparedStatement, int i, OrderStatus orderStatus, JdbcType jdbcType) throws SQLException {
        preparedStatement.setInt(i,orderStatus.getCode());
    }

    @Override
    public OrderStatus getNullableResult(ResultSet resultSet, String s) throws SQLException {
        return OrderStatus.search(resultSet.getInt(s));
    }

    @Override
    public OrderStatus getNullableResult(ResultSet resultSet, int i) throws SQLException {
        return OrderStatus.search(resultSet.getInt(i));
    }

    @Override
    public OrderStatus getNullableResult(CallableStatement callableStatement, int i) throws SQLException {
        return OrderStatus.search(callableStatement.getInt(i));
    }
}
